home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / lisp / hyperbole / kotl / kotl.el < prev    next >
Encoding:
Text File  |  1995-07-08  |  6.1 KB  |  179 lines

  1. ;;!emacs
  2. ;;
  3. ;; FILE:         kotl.el
  4. ;; SUMMARY:      Internal representation of outline kcells used by kviews.
  5. ;; USAGE:        GNU Emacs Lisp Library
  6. ;; KEYWORDS:     outlines, wp
  7. ;;
  8. ;; AUTHOR:       Kellie Clark & Bob Weiner
  9. ;;
  10. ;; ORIG-DATE:    5/1/93
  11. ;; LAST-MOD:      7-Jul-95 at 14:22:33 by Bob Weiner
  12. ;;
  13. ;; This file is part of Hyperbole.
  14. ;; Available for use and distribution under the same terms as GNU Emacs.
  15. ;;
  16. ;; Copyright (C) 1993-1995, Free Software Foundation, Inc.
  17. ;; Developed with support from Motorola Inc.
  18. ;;
  19. ;; DESCRIPTION:  
  20. ;;
  21. ;; DESCRIP-END.
  22.  
  23. ;;; ************************************************************************
  24. ;;; Other required Elisp libraries
  25. ;;; ************************************************************************
  26.  
  27. (mapcar 'require '(klabel knode hinit htz))
  28.  
  29. ;;; ************************************************************************
  30. ;;; Public variables
  31. ;;; ************************************************************************
  32.  
  33. ;;; ************************************************************************
  34. ;;; Public functions
  35. ;;; ************************************************************************
  36.  
  37. ;;;
  38. ;;; kcell
  39. ;;;
  40.  
  41. (fset 'kcell:contents     'knode:contents)
  42.  
  43. (defun kcell:copy (kcell)
  44.   "Return a copy of KCELL."
  45.   (knode:copy kcell))
  46.  
  47. (defun kcell:create (contents idstamp &optional plist)
  48.   "Return a new kcell which stores CONTENTS (a string or nil), has permanent IDSTAMP (an integer), and optional additional property list, PLIST.
  49. User id of `creator' of cell and `create-time' are added to cell's PLIST if
  50. not already there."
  51.   (and contents (not (stringp contents))
  52.        (error "(kcell:create): Invalid `contents' argument: %s" contents))
  53.   (if (or (not (integerp idstamp)) (< idstamp 0))
  54.       (error "(kcell:create): Invalid `idstamp' argument: %s" idstamp))
  55.   (knode:create
  56.    contents (nconc (list 'idstamp idstamp)
  57.            (if (memq 'creator plist)
  58.                nil
  59.              (list 'creator (concat (user-login-name)
  60.                         hyperb:host-domain)
  61.                'create-time (htz:date-sortable-gmt)))
  62.            plist)))
  63.  
  64. (defun kcell:create-top (&optional file counter)
  65.   "Return a new koutline top cell optionally attached to FILE with current idstamp COUNTER."
  66.   (kcell:create nil 0
  67.         ;; id-counter = max idstamp value given out in this kotl
  68.         (list 'id-counter (or counter 0) 'file file)))
  69.  
  70. (defun kcell:get-attr (kcell attribute)
  71.   "Return the value of KCELL's ATTRIBUTE."
  72.   (knode:get-attr (kcell:plist kcell) attribute))
  73.  
  74. (defun kcell:idstamp (kcell)
  75.   "Return permanent idstamp of KCELL as an integer."
  76.   (kcell:get-attr kcell 'idstamp))
  77.  
  78. (fset 'kcell:is-p      'knode:is-p)
  79.  
  80. (defun kcell:plist (kcell)
  81.   (knode:get-attr kcell 'plist))
  82.  
  83. (defun kcell:ref-to-id (cell-ref)
  84.   "Returns a CELL-REF string converted to a cell identifier string.
  85. If CELL-REF contains both a relative and a permanent id, the permanent id is
  86. returned.  If CELL-REF is invalid, nil is returned.
  87.  
  88. CELL-REF may be of any of the following forms:
  89.   1b       - relative id, augment style
  90.   1.2      - relative id, legal style
  91.   012      - permanent idstamp
  92.   1a=012   - both relative and permanent ids (in that order) separated by =."
  93.  
  94.   (cond ((not (stringp cell-ref)) nil)
  95.     ((string-match "[^.= \t\n0-9a-zA-Z]" cell-ref) nil)
  96.     ((string-match "^\\s *\\([.0-9a-zA-Z]+\\)=\\(0[0-9]*\\)\\s *$" cell-ref)
  97.      (substring cell-ref (match-beginning 2) (match-end 2)))
  98.     ((string-match "^\\s *\\([.0-9a-zA-Z]+\\)\\s *$" cell-ref)
  99.      (substring cell-ref (match-beginning 1) (match-end 1)))))
  100.  
  101. (defun kcell:remove-attr (kcell attribute)
  102.   "Remove KCELL's ATTRIBUTE, if any, return modified KCELL."
  103.   (knode:set-attr
  104.    kcell 'plist (knode:remove-attr (kcell:plist kcell) attribute)))
  105.  
  106. (defun kcell:set-attr (kcell attribute value)
  107.   "Set KCELL's ATTRIBUTE to VALUE and return modified KCELL."
  108.   (knode:set-attr
  109.    kcell 'plist (knode:set-attr (kcell:plist kcell)
  110.                 attribute value)))
  111.  
  112. (defun kcell:set-create-time (kcell)
  113.   "Store the time of creation of KCELL."
  114.   (kcell:set-attr kcell 'create-time (htz:date-sortable-gmt)))
  115.  
  116. (defun kcell:set-creator (kcell)
  117.   "Store the current user's id as the creator of KCELL."
  118.   (kcell:set-attr
  119.    kcell 'creator (concat (user-login-name) hyperb:host-domain)))
  120.  
  121. (defun kcell:set-idstamp (kcell idstamp)
  122.   "Set KCELL's permanent IDSTAMP (an integer) and return IDSTAMP."
  123.   (kcell:set-attr kcell 'idstamp idstamp)
  124.   (kcell:idstamp kcell))
  125.  
  126. ;;;
  127. ;;; kotl-data - Persistent representation of kotl cells (written to files).
  128. ;;;
  129.  
  130. (defun kotl-data:create (cell)
  131.   "Given a kotl CELL, return a kotl-data structure to write to a file.
  132. If CELL, its idstamp, or its property list are nil, this repairs the cell by
  133. assuming it is the cell at point and filling in the missing information."
  134.    (let ((idstamp (kcell:idstamp cell))
  135.      (plist (nthcdr 2 (kcell:plist cell))))
  136.      (if (and cell idstamp plist)
  137.      (vector idstamp plist)
  138.        (kotl-data:create
  139.     (kcell:create nil
  140.               (or idstamp (kview:id-increment kview))
  141.               plist)))))
  142.  
  143. (defun kotl-data:idstamp (kotl-data)
  144.   (aref kotl-data 0))
  145.  
  146. (defun kotl-data:plist-v2 (kotl-data)
  147.   (aref kotl-data 2))
  148.  
  149. (defun kotl-data:plist-v3 (kotl-data)
  150.   (aref kotl-data 1))
  151.  
  152. (defun kotl-data:to-kcell-v2 (kotl-data)
  153.   (if (vectorp kotl-data)
  154.       (kcell:create
  155.        ;; Cell contents are no longer put into cells themselves by default
  156.        ;; when a file is read.  The contents are stored within the kview
  157.        ;; buffer, so use nil as a place-holder.
  158.        nil
  159.        ;; Repair invalid idstamps on the fly.
  160.        (or (kotl-data:idstamp kotl-data) (kview:id-increment kview))
  161.        (kotl-data:plist-v2 kotl-data))
  162.     ;; Repair invalid cells on the fly.
  163.     (kcell:create nil (kview:id-increment kview))))
  164.  
  165. (defun kotl-data:to-kcell-v3 (kotl-data)
  166.   (if (vectorp kotl-data)
  167.       (kcell:create
  168.        ;; Cell contents are no longer put into cells themselves by default
  169.        ;; when a file is read.  The contents are stored within the kview
  170.        ;; buffer, so use nil as a place-holder.
  171.        nil
  172.        ;; Repair invalid idstamps on the fly.
  173.        (or (kotl-data:idstamp kotl-data) (kview:id-increment kview))
  174.        (kotl-data:plist-v3 kotl-data))
  175.     ;; Repair invalid cells on the fly.
  176.     (kcell:create nil (kview:id-increment kview))))
  177.  
  178. (provide 'kotl)
  179.